﻿@model ProductReviewOverviewModel
@using System.Globalization
@using Nop.Web.Models.Catalog;
@{
    int ratingPercent = 0;
    if (Model.TotalReviews != 0)
    {
        ratingPercent = ((Model.RatingSum * 100) / Model.TotalReviews) / 5;
    }
}
@if (Model.AllowCustomerReviews)
{
    <div class="product-reviews-overview" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
        @*<div class="product-review-box">
            <div class="rating">
                <div style="width: @(ratingPercent)%">
                </div>
            </div>
        </div>*@

                @{

                    double ratingNumber= 0;
                    int fullStar = 0;
                    double fractionNumber = 0;
                    int fractionStar = 0;
                    int emptyStar = 0;

                    if(Model.TotalReviews != 0)
                    {
                        ratingNumber = ((Model.RatingSum * 100.0) / Model.TotalReviews)/100.0 ;
                    }
                    fullStar = (int)ratingNumber;
                    fractionNumber = ratingNumber - fullStar;
                    
                    if(fractionNumber > 0.75)
                    {
                        fullStar++;
                    } else if(fractionNumber > 0.25 && fractionStar < 0.75)
                    {
                        fractionStar++;
                    }else if (fractionNumber>0 && fractionNumber < 0.25)
                    {
                        emptyStar++;
                    }
                    
                    emptyStar += (5 - fullStar - fractionStar);

                    <div class="rating-div hide-on-grid">
                        
                    
                        @for (int i = 0; i <fullStar; i++)
                        {
                            <i class="fa fa-star"></i>

                        }
                        @for (int i = 0; i <fractionStar; i++)
                        {
                            <i class="fa fa-star-half-full"></i>

                        }
                        @for (int i = 0; i <emptyStar; i++)
                        {
                            <i class="fa fa-star-o"></i>

                        }
                    </div>



                    

                }

        @if (Model.TotalReviews > 0)
        {
            <div class="product-review-links">
                <a href="@Url.RouteUrl("ProductReviews", new { productId = Model.ProductId })">@Model.TotalReviews
                    @T("Reviews.Overview.Reviews")</a> <span class="separator">|</span> <a href="@Url.RouteUrl("ProductReviews", new { productId = Model.ProductId })">@T("Reviews.Overview.AddNew")</a>
            </div>
            @*hidden microdata info*@
            decimal ratingValue = ratingPercent / (decimal)20;
            <span itemprop="ratingValue" style="display: none;">@ratingValue.ToString("0.0", new CultureInfo("en-US"))</span>
            <span itemprop="reviewCount" style="display: none;">@Model.TotalReviews</span>
        }
        else
        {
            <div class="product-no-reviews">
                <a href="@Url.RouteUrl("ProductReviews", new { productId = Model.ProductId })">@T("Reviews.Overview.First")</a>
            </div>
        }
    </div>
}